#include <nxos.h>

NX_Error TEST_Fifo(char *cmdline)
{
    const char * str = "hello, world!";
    char buf[48];
    NX_Size len;

    NX_Solt solt = NX_FifoCreate(32);
    if (solt < 0)
    {
        NX_Printf("fifo create failed %s\n", NX_ErrorToString(NX_ErrorGet()));
    }
    len = NX_FifoWrite(solt, (const NX_U8 *)str, 32);
    NX_Printf("fifo: write:%d\n", len);
    len = NX_FifoLength(solt);
    NX_Printf("fifo: len:%d\n", len);
    
    len = NX_FifoWrite(solt, (const NX_U8 *)str, 32);
    NX_Printf("fifo: write:%d\n", len);
    len = NX_FifoLength(solt);
    NX_Printf("fifo: len:%d\n", len);
    
    len = NX_FifoRead(solt, (const NX_U8 *)buf, 32);
    NX_Printf("fifo: read:%d: %s\n", len, buf);
    len = NX_FifoLength(solt);
    NX_Printf("fifo: len:%d\n", len);
    
    NX_MemZero(buf, 48);
    len = NX_FifoRead(solt, (const NX_U8 *)buf, 32);
    NX_Printf("fifo: read:%d: %s\n", len, buf);
    len = NX_FifoLength(solt);
    NX_Printf("fifo: len:%d\n", len);
    
    NX_SoltClose(solt);

    return NX_EOK;
}
